package com.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.MusicType;
import com.service.MusicTypeService;

@RequestMapping("/musicType")
@Controller
public class MusicTypeController {

	@Autowired
	private MusicTypeService musicTypeService;
	
	@RequestMapping("/musicType_show")
	public String musicType_show(Model model) {
		List<Map<String, Object>> musicTypeList = musicTypeService.queryMusicType();
		model.addAttribute("musicTypeList", musicTypeList);
		return "admin/musicType";
	}
	
	@RequestMapping("/musicType_add_show")
	public String musicType_add_show(){
		return "admin/musicType-add";
	}
	
	@RequestMapping("/musicType_add_submit")
	public String musicType_add_submit(MusicType musicType){
		musicTypeService.addMusicType(musicType);
		return "admin/musicType-add";
	}
	
	@RequestMapping("/musicType_update_show")
	public String musicType_update_show(Integer musicTypeId,Model model){
		Map<String, Object> musicTypeMap = musicTypeService.queryMusicTypeId(musicTypeId);
		model.addAttribute("musicTypeMap", musicTypeMap);
		return "admin/musicType-edit";
	}
	
	@RequestMapping("/musicType_update_submit")
	public String musicType_update_submit(MusicType musicType){
		musicTypeService.editMusicType(musicType);
		return "admin/musicType-edit";
	}
	
	@RequestMapping("/musicType_delete")
	public String musicType_delete(Integer musicTypeId){
		musicTypeService.delMusicType(musicTypeId);
		return "admin/musicType";
	}
}
